import request from '../utils/request';
//import {stringify} from 'qs'

interface Credentials {
    [index: string]: string;
    user: string;
    password: string;
}
interface AddUserRequest {
    user: {
        name: string;
        phone: number;
        type: number;
        restMoney: number;
        vehicleLicense: string;
    };
}
interface EditUserRequest {
    phone: number;
    user: {
        name: string;
        phone: number;
        type: 2;
        restMoney: number;
    };
}
interface EditTransactionRequest {
    id: number;
    transaction: {
        type: string;
        cost: number;
        date: string;
        license: string;
        phone: number;
        payMethod: number;
    };
}
interface AddMoneyRequest {
    phone: number;
    money: number;
}
interface AddTransactionRequest {
    transaction: {
        type: string;
        cost: number;
        date: string;
        license: string;
        phone: number;
        payMethod: number;
    };
}
interface Response {
    [index: string]: any;
    success: boolean;
    msg: string;
    obj: any;
}
interface UserList extends Response {
    obj: Array < {
        id: number;
        name: string;
        phone: number;
        type: 1;
        restMoney: number;
        vehicleLicense: string;
    } >;
}
interface TransactionList extends Response {
    obj: Array < {
        id: number;
        type: string;
        cost: number;
        date: string;
        license: string;
        phone: number;
        payMethod: number; //支付方式
    } >;
}
// 登录
export async function login(credentials: Credentials): Promise < Response > {
    return request('api/car_wash/v1/login', {
        method: 'POST',
        body: credentials
    });
}
// 添加用户
export async function addUser(user: AddUserRequest): Promise < Response > {
    return request('api/car_wash/v1/user', {
        method: 'POST',
        body: user
    });
}
// 查询用户
export async function queryUser(): Promise < UserList > {
    return request(`api/car_wash/v1/user`);
}
// 修改用户
export async function editUser(user: EditUserRequest): Promise < Response > {
    return request('api/car_wash/v1/user', {
        method: 'PUT',
        body: user
    });
}
// 删除用户
export async function deleteUser(id: number): Promise < Response > {
    return request(`api/car_wash/v1/user/${id}`, { method: 'DELETE' });
}
// 充值
export async function addMoney(user: AddMoneyRequest): Promise < Response > {
    return request(`api/car_wash/v1/user/money`, {
        method: 'POST',
        body: user
    });
}
// 查询交易
export async function queryTransaction(): Promise < Response > {
    return request('api/car_wash/v1/transaction');
}
// 新增交易
export async function addTransaction(transaction: AddTransactionRequest): Promise < Response > {
    return request('api/car_wash/v1/transaction', {
        method: 'POST',
        body: transaction
    });
}
// 修改交易
export function editTransaction(transaction: EditTransactionRequest): Promise < Response > {
    return request('api/car_wash/v1/transaction', {
        method: 'PUT',
        body: transaction
    });
}
// 删除交易
export function deleteTransaction(id: number): Promise < Response > {
    return request(`api/car_wash/v1/transaction/${id}`, { method: 'DELETE' });
}
